package geektime.spring.springbucks.controller;

import geektime.spring.springbucks.entity.TOrderCoffee;
import geektime.spring.springbucks.service.TOrderCoffeeService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (TOrderCoffee)表控制层
 *
 * @since 2022-10-30 00:17:43
 */
@RestController
@RequestMapping("tOrderCoffee")
public class TOrderCoffeeController {
    /**
     * 服务对象
     */
    @Resource
    private TOrderCoffeeService tOrderCoffeeService;

    /**
     * 分页查询
     *
     * @param tOrderCoffee 筛选条件
     * @param pageRequest  分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<TOrderCoffee>> queryByPage(TOrderCoffee tOrderCoffee, PageRequest pageRequest) {
        return ResponseEntity.ok(this.tOrderCoffeeService.queryByPage(tOrderCoffee, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<TOrderCoffee> queryById(@PathVariable("id") String id) {
        return ResponseEntity.ok(this.tOrderCoffeeService.queryById());
    }

    /**
     * 新增数据
     *
     * @param tOrderCoffee 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<TOrderCoffee> add(TOrderCoffee tOrderCoffee) {
        return ResponseEntity.ok(this.tOrderCoffeeService.insert(tOrderCoffee));
    }

    /**
     * 编辑数据
     *
     * @param tOrderCoffee 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<TOrderCoffee> edit(TOrderCoffee tOrderCoffee) {
        return ResponseEntity.ok(this.tOrderCoffeeService.update(tOrderCoffee));
    }

    /**
     * 删除数据
     *
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById() {
        return ResponseEntity.ok(this.tOrderCoffeeService.deleteById());
    }

}

